//Page 340
/* to make your own class adaptable to be a 
   adaptable function object, you shoud
   a) inherits unary_function for unary func obj.
   b) make operator() to be const
*/

#include <algorithm>
#include <cstddef>
#include <functional>
#include <iostream>

using namespace std ;

class equal_20 : public unary_function<int, bool>
{
public:
	bool operator() (int n) const //NoteA: const is necessary, orelse can't be compiled.
	{
		return n == 20 ;
	}
};

int main()
{
	int a[] = {10, 20, 30, 40};
	const size_t SIZE = sizeof a / sizeof a[0] ;
	cout << "call lib equal_to: " << count_if ( a, a+SIZE, not1(bind1st(equal_to<int>(), 20))) << endl;
	
	cout << "---1: my equal_to: " << count_if ( a, a+SIZE, not1(equal_20()) ) << endl; //Abide by NoteA.
	
	equal_20 ee;
	cout << "---2: my equal_to: " << count_if ( a, a+SIZE, not1(ee) ) << endl; //Abide by NoteA.

	return 0 ;
}

